
class RemoveCommentsPlugin {
  apply (compiler) {
    console.log('RemoveCommmentsPlugin starting')
    compiler.hooks.emit.tap('RemoveCommentsPlugin', compilation => {
      for (const name in compilation.assets) {
        // console.log(name + 'content: ', compilation.assets[name].source());
        if (name.endsWith('.js')) {
          const contents = compilation.assets[name].source();
          const noComments = contents.replace(/\/\*{2,}\/\s?/g, '');
          compilation.assets[name] = {
            source: () => noComments,
            size: () => noComments.length,
          }
        }
      }
    })
  }
}

module.exports = RemoveCommentsPlugin;